<template>
	<view class="user">
		<!-- 上方显示用户信息的区域 -->
		<view class="userinfo">
			<!-- 信息区域 -->
			<view class="top">
				<view class="avator">
					<uni-icons type="person-filled" size="30" :color="logColor"></uni-icons>
				</view>
				<view class="uname" v-if="store.isLogin">
					<view>{{store.userInfo.username}}</view>
					<view>{{store.userInfo.mobile}}</view>
				</view>
				<view class="uname" v-else @tap="toLogin">点击登录</view>
			</view>
		</view>
		<!-- 下方显示的四项用户操作项 -->
		<view class="list">
			<uni-list>
				<uni-list-item v-for="item,index in manageList" :title="item.name" :show-extra-icon="true"
					:extra-icon="item.icon" clickable link @tap="navto(index)"></uni-list-item>
			</uni-list>
		</view>
	</view>
</template>

<script setup>
	import {
		ref
	} from 'vue'
	import { userStore } from '../../store/userStore';


	// 创建状态库
	let store = userStore()
	let mystore = userStore()
	let logColor = ref("#ccc")
	const manageList = ref([{
		name: '订单管理',
		icon: {
			color: '#56c48b',
			size: '22',
			type: 'shop'
		}
	}, {
		name: '地址管理',
		icon: {
			color: '#ff6700',
			size: '22',
			type: 'location-filled'
		}
	}, {
		name: '我的收藏',
		icon: {
			color: '#0225ff',
			size: '22',
			type: 'star'
		}
	}, {
		name: '设置',
		icon: {
			color: '#0081b9',
			size: '22',
			type: 'gear'
		}
	}])

	function navto(index) {

		uni.showToast({
			title: `你点击的是${manageList.value[index].name}`
		})
	}

	function toLogin() {
		uni.navigateTo({
			url: "/pages/login/login"
		})
	}
</script>

<style lang="scss">
	/* 用户信息区域样式 */
	.user {
		display: flex;
		flex-direction: column;
		align-items: center;
		width: 100%;
		padding: 20px;
		box-sizing: border-box;
	}

	.userinfo {
		display: flex;
		flex-direction: column;
		align-items: center;
		width: 100%;
	}

	.top {
		display: flex;
		align-items: center;
		margin-bottom: 20px;
	}

	.avator {
		display: flex;
		justify-content: center;
		align-items: center;
		width: 60px;
		height: 60px;
		border-radius: 50%;
		background-color: #f0f0f0;
		/* 头像背景颜色 */
		margin-right: 20px;
	}

	.avator uni-icons {
		font-size: 30px;
		color: #007AFF;
		/* 图标颜色 */
	}

	.uname {
		display: flex;
		flex-direction: column;
		font-size: 16px;
		color: #333;
	}

	.uname view:not(:last-child) {
		margin-bottom: 5px;
	}

	/* 用户操作项样式 */
	.list {
		width: 100%;
	}

	uni-list {
		width: 100%;
	}

	uni-list-item {
		padding: 15px 0;
		border-bottom: 1px solid #eee;
		/* 分割线 */
	}

	uni-list-item:last-child {
		border-bottom: none;
	}

	uni-list-item:active {
		background-color: #f0f0f0;
		/* 点击时的背景颜色 */
	}

	/* 登录提示样式 */
	.uname v-else {
		padding: 10px;
		border: 1px solid #007AFF;
		/* 边框颜色 */
		border-radius: 4px;
		color: #007AFF;
		/* 文字颜色 */
		text-align: center;
		cursor: pointer;
	}

	.uname v-else:active {
		background-color: #f0f0f0;
		/* 点击时的背景颜色 */
	}
</style>